/*************************************************
  * 描述：
  *
  * File：hotkeytest.h
  * Author：chenyujin@mozihealthcare.cn
  * Date：2025/9/10
  * Update：
  * ************************************************/
#ifndef HOTKEYTEST_H
#define HOTKEYTEST_H

#include <QAbstractNativeEventFilter>
#include <QApplication>
#include <QtTest/QtTest>
#include <common/hotkey/hotkey.h>
#include <common/logger/logger.h>

class GlobalKeyFilter : public QObject, public QAbstractNativeEventFilter
{
	Q_OBJECT
public:
	GlobalKeyFilter()
	{
	}

	void install()
	{
		if (qApp && qApp->eventDispatcher())
		{
			qApp->eventDispatcher()->installNativeEventFilter(this);
		}
		else
		{
			LOG_ERROR("qApp or qApp->eventDispatcher() is nullptr");
		}
	}

	bool nativeEventFilter(const QByteArray& eventType, void* message, long* result) override
	{
#ifdef Q_OS_WIN
		if (eventType == "windows_generic_MSG")
		{
			MSG* msg = static_cast<MSG*>(message);
			if (msg->message == WM_HOTKEY)
			{
				emit hotKeyStriked(msg->wParam);
				return true;
			}
		}
#endif
		return false;
	}

signals:
	void hotKeyStriked(uint16_t id);
};

class HotKeyTest final : public QObject
{
	Q_OBJECT
public:
	explicit HotKeyTest(QObject* parent = nullptr);
	~HotKeyTest() override;

private slots:
	void initTestCase();
	void tstHotKey();
	void cleanupTestCase();

private:
	GlobalKeyFilter* m_filter = nullptr;
};

#endif// HOTKEYTEST_H
